package com.snake.controller;

import com.snake.enums.Direction;
import com.snake.pojo.GameState;
import com.snake.service.SnakeGameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/snakeGame")
public class SnakeGameController {

    @Autowired
    private SnakeGameService snakeGameService;

    @GetMapping("/state")
    public GameState getGameState() {
        return snakeGameService.getGameState();
    }

    @PostMapping("/move")
    public GameState move() {
        return snakeGameService.move();
    }

    @PostMapping("/direction")
    public void changeDirection(@RequestParam Direction direction) {
        snakeGameService.changeDirection(direction);
    }

    @PostMapping("/reset")
    public GameState resetGame() {
        snakeGameService.resetGame();
        return snakeGameService.getGameState();
    }
}
